package thread;

import java.util.concurrent.TimeUnit;

/**
 * created by lanwp on 2019/2/26.
 * 1.可见性 2.原子性 3.有序性
 * 多线程：可见性
 */
public class VisbleDemo{

//    private static boolean stop = false; // 多线程可见性问题
    private volatile static boolean stop = false;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            int i = 0;
            while (!stop) {
                ++i;
            }
        });
        t.start();
        TimeUnit.SECONDS.sleep(1);
        stop = true; // 可见性问题
        System.out.println("程序結束： stop=" + stop);
    }

}
